package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsNarratorThemeApplicantDetail;
import com.macro.mall.dto.BmsNarratorThemeApplicantParam;
import com.macro.mall.model.BmsNarratorThemeApplicant;
import com.macro.mall.service.BmsNarratorThemeApplicantService;
import com.macro.mall.utils.ExcelUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.net.URLEncoder;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

@Controller
@Api(tags = "BmsNarratorThemeApplicantController")
@Tag(name = "BmsNarratorThemeApplicantController", description = "讲解项目-主题-预约记录")
@RequestMapping("/narratorThemeApplicant")
public class BmsNarratorThemeApplicantController {

    @Autowired
    private BmsNarratorThemeApplicantService bmsNarratorThemeApplicantService;

    @ApiOperation("分页查询讲解项目-主题-预约记录")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsNarratorThemeApplicant>> getList(@RequestBody BmsNarratorThemeApplicantParam bmsNarratorThemeApplicantParam) {
        List<BmsNarratorThemeApplicant> bmsNarratorThemeApplicantList = bmsNarratorThemeApplicantService.getList(bmsNarratorThemeApplicantParam);
        return CommonResult.success(CommonPage.restPage(bmsNarratorThemeApplicantList));
    }

    @ApiOperation("根据id获取讲解项目-主题-预约记录信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsNarratorThemeApplicantDetail> getItem(@PathVariable Long id) {
        BmsNarratorThemeApplicantDetail bmsNarratorThemeApplicantDetail = bmsNarratorThemeApplicantService.getItem(id);
        return CommonResult.success(bmsNarratorThemeApplicantDetail);
    }
    
    @ApiOperation("分页查询讲解项目-主题-预约记录")
    @RequestMapping(value = "/export", method = RequestMethod.POST)
    public void export(@RequestBody BmsNarratorThemeApplicantParam bmsNarratorThemeApplicantParam, HttpServletResponse response) throws Exception {
        List<BmsNarratorThemeApplicant> bmsNarratorThemeApplicantList = bmsNarratorThemeApplicantService.getExportList(bmsNarratorThemeApplicantParam);
    	String fileName = URLEncoder.encode("预约记录.xlsx", "UTF-8");
    	response.setCharacterEncoding("utf-8");
    	ExcelUtils.write(response, fileName, "预约记录", bmsNarratorThemeApplicantList, BmsNarratorThemeApplicant.class);
    }



}
